
package com.zcp.wizard;

import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.util.Log;

public class GpsUtils {

    public static final String TAG = "GpsUtils";

    public static void toggleGps(Context context,boolean switcher) {
            Log.i("tag1", android.os.Build.VERSION.SDK_INT+" ||gps");
            try {
                Intent gpsIntent = new Intent();
                gpsIntent.setClassName("com.android.settings",
                        "com.android.settings.widget.SettingsAppWidgetProvider");
                gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
                gpsIntent.setData(Uri.parse("custom:3"));
                PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send();
            } catch (CanceledException e) {
                e.printStackTrace();
            }
            //2.2在Settings.Secure 可以直接设置的，但是虽说是开放的，但是还是不能使用，因为经过测试发现需要系统签名，而这个需要改系统源码才行。
    }

    public static boolean isGPSEnable(Context context) {
        boolean status = false;
        try {
            LocationManager locationManager = (LocationManager) context
                    .getSystemService(Context.LOCATION_SERVICE);
            status = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return status;
        // boolean res = false;
        // String str = Settings.Secure.getString(context.getContentResolver(),
        // Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        // if (str != null) {
        // if (str.contains("gps")) {
        // res = true;
        // }
        // }
    }

}
